home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / resource / c / getrusage < prev    next >
Text File  |  1996-11-09  |  4KB  |  106 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/resource/c/RCS/getrusage,v $
  4.  * $Date: 1996/10/30 21:59:00 $
  5.  * $Revision: 1.4 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: getrusage,v $
  10.  * Revision 1.4  1996/10/30 21:59:00  unixlib
  11.  * Massive changes made by Nick Burret and Peter Burwood.
  12.  *
  13.  * Revision 1.3  1996/09/16 21:23:52  unixlib
  14.  * CL_0002 Nick Burret
  15.  * Minor changes to file handling
  16.  * Change most error numbers, and use in assembler sources (SJC)
  17.  * Various minor bug fixes and compatability changes.
  18.  *
  19.  * Revision 1.2  1996/05/06 09:01:33  unixlib
  20.  * Updates to sources made by Nick Burrett, Peter Burwood and Simon Callan.
  21.  * Saved for 3.7a release.
  22.  *
  23.  * Revision 1.1  1996/04/19 21:29:28  simon
  24.  * Initial revision
  25.  *
  26.  * Written by Nick Burrett, 18 Feb 1996.
  27.  ***************************************************************************/
  28.  
  29. static const char rcs_id[] = "$Id: getrusage,v 1.4 1996/10/30 21:59:00 unixlib Rel $";
  30.  
  31. #include <sys/resource.h>
  32. #include <sys/unix.h>
  33. #include <errno.h>
  34.  
  35.  
  36. /* Return resource usage information on process indicated by WHO
  37.    and put it in *USAGE.  Returns 0 for success, -1 for failure.  */
  38. int
  39. getrusage (enum __rusage_who who, struct rusage *usage)
  40. {
  41.   int time;
  42.  
  43.   if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
  44.     {
  45.       errno = EINVAL;
  46.       return -1;
  47.     }
  48.  
  49.   if (usage == 0)
  50.     return -1;
  51.  
  52.   time = (int) clock ();
  53.   /* Since clock () returns all time the current program has been
  54.      running for, we shall not bother with the ru_stime structure.  */
  55.   /* Time spend executing user instructions.  */
  56.   usage->ru_utime.tv_sec = time / 100;
  57.   /* Separate the centiseconds from the seconds and then convert
  58.      to microseconds.  */
  59.   usage->ru_utime.tv_usec = (time - ((int)(time / 100) * 100)) * 10000;
  60.   /* Time spend in operating system code on behalf of 'who'.  */
  61.   usage->ru_stime.tv_sec = 0;
  62.   usage->ru_stime.tv_usec = 0;
  63.   /* The maximum residet set size used, in kilobytes i.e. the
  64.      maximum number of kilobytes that 'who' used in real memory
  65.      simultaneously.  */
  66.   usage->ru_maxrss = 0;
  67.   /* Amount of memory used by text that was shared with other
  68.      processes. Expressed in kilobytes * ticks of execution.  */
  69.   usage->ru_ixrss = 0;
  70.   /* The amount of unshared memory used in data.
  71.      Expressed as above.  */
  72.   usage->ru_idrss = 0;
  73.   /* The amount of unshared memory used in stack space.
  74.      Expressed as above.  */
  75.   usage->ru_isrss = 0;
  76.   /* The number of page faults which were serviced without
  77.      requiring any I/O.  */
  78.   usage->ru_minflt = 0;
  79.   /* The number of page faults which were serviced by doing I/O.  */
  80.   usage->ru_majflt = 0;
  81.   /* The number of times 'who' was swapped entirely out of main
  82.      memory.  */
  83.   usage->ru_nswap = 0;
  84.   /* The number of times the file system had to read from the disk
  85.      on behalf of 'who'.  */
  86.   usage->ru_inblock = __u->usage.ru_inblock;
  87.   /* The number of times the file system had to write to the disk
  88.      on behalf of 'who'.  */
  89.   usage->ru_oublock = __u->usage.ru_oublock;
  90.   /* Number of IPC messages sent.  */
  91.   usage->ru_msgsnd = 0;
  92.   /* Number of IPC messages received.  */
  93.   usage->ru_msgrcv = 0;
  94.   /* Number of signals received.  */
  95.   usage->ru_nsignals = __u->usage.ru_nsignals;
  96.   /* Number of times 'who' voluntarily invoked a context switch
  97.      (usually to wait for some service).  */
  98.   usage->ru_nvcsw = 0;
  99.   /* The number of times an involuntary context switch took place
  100.      (because the time slice expired, or another process of higher
  101.      priority became runnable).  */
  102.   usage->ru_nivcsw = 0;
  103.  
  104.   return 0;
  105. }
  106.